﻿@using CarCareTracker.Helper
@inject IConfigHelper config
@inject ITranslationHelper translator
@model StickerViewModel
@{
    var userConfig = config.GetUserConfig(User);
    var hideZero = userConfig.HideZero;
    var userLanguage = userConfig.UserLanguage;
}
@if( Model.ReminderRecords.Any()){
    @foreach(ReminderRecord reminder in Model.ReminderRecords){
        <div class="reminderSticker">
            <div class="row justify-content-center mt-2">
                <img src="@config.GetLogoUrl()" class="lubelogger-logo-sticker" />
            </div>
            <div class="row">
                <div class="col-12 text-center">
                    <p class="display-1">@($"{Model.VehicleData.Year} {Model.VehicleData.Make} {Model.VehicleData.Model}")</p>
                </div>
            </div>
            <div class="row">
                <div class="col-12 text-center">
                    <p class="display-2">@($"{StaticHelper.GetVehicleIdentifier(Model.VehicleData)}")</p>
                </div>
            </div>
                <div class="row">
                    <div class="col-12 text-center">
                        <p class="display-2 text-uppercase fw-bold">@($"{reminder.Description}")</p>
                    </div>
                </div>
                @if (reminder.Metric == ReminderMetric.Odometer || reminder.Metric == ReminderMetric.Both)
                {
                    <div class="row">
                        <div class="col-12 text-center">
                            <p class="display-2">@($"{translator.Translate(userLanguage, "Odometer")}")</p>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-12 text-center">
                            <p class="display-2 fw-bold">@($"{reminder.Mileage}")</p>
                        </div>
                    </div>
                }
                @if (reminder.Metric == ReminderMetric.Date || reminder.Metric == ReminderMetric.Both)
                {
                    <div class="row">
                        <div class="col-12 text-center">
                            <p class="display-2">@($"{translator.Translate(userLanguage, "Date")}")</p>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-12 text-center">
                            <p class="display-2 fw-bold">@($"{reminder.Date.ToShortDateString()}")</p>
                        </div>
                    </div>
                }
                @if (reminder.Metric == ReminderMetric.Both)
                {
                    <div class="row">
                        <div class="col-12 text-center">
                            <p class="display-2 text-uppercase">@($"{translator.Translate(userLanguage, "Whichever comes first")}")</p>
                        </div>
                    </div>
                }
        </div>
    }
} else if (Model.GenericRecords.Any()){
    @foreach(GenericRecord genericRecord in Model.GenericRecords){
        <div class="d-flex flex-column recordSticker">
            <div class="d-flex">
                <img src="@config.GetLogoUrl()" class="lubelogger-logo" />
            </div>
            <hr />
            <div class="row">
                <div class="col-6">
                    <ul class="list-group">
                        <li class="list-group-item">
                            <span class="display-6">@($"{Model.VehicleData.Year} {Model.VehicleData.Make} {Model.VehicleData.Model}")</span>
                        </li>
                        <li class="list-group-item">
                            <span class="lead">@($"{StaticHelper.GetVehicleIdentifier(Model.VehicleData)}")</span>
                        </li>
                        @foreach (ExtraField extraField in Model.VehicleData.ExtraFields)
                        {
                            if (!string.IsNullOrWhiteSpace(extraField.Value))
                            {
                                <li class="list-group-item">
                                    <span class="lead">@($"{extraField.Name}: {extraField.Value}")</span>
                                </li>
                            }
                        }
                    </ul>
                </div>
                <div class="col-6">
                    <ul class="list-group">
                        @if(!string.IsNullOrWhiteSpace(genericRecord.Description)){
                            <li class="list-group-item">
                                @($"{translator.Translate(userLanguage, "Description")}: {genericRecord.Description}")
                            </li>
                        }
                        @switch(Model.RecordType){
                            case ImportMode.ServiceRecord:
                            case ImportMode.RepairRecord:
                            case ImportMode.UpgradeRecord:
                            case ImportMode.GasRecord:
                                <li class="list-group-item">
                                    @($"{translator.Translate(userLanguage, "Date")}: {genericRecord.Date.ToShortDateString()}")
                                </li>
                                <li class="list-group-item">
                                    @($"{translator.Translate(userLanguage, "Odometer")}: {genericRecord.Mileage}")
                                </li>
                                <li class="list-group-item">
                                    @($"{translator.Translate(userLanguage, "Cost")}: {genericRecord.Cost.ToString("C")}")
                                </li>
                            break;
                            case ImportMode.TaxRecord:
                            case ImportMode.PlanRecord:
                                <li class="list-group-item">
                                    @($"{translator.Translate(userLanguage, "Date")}: {genericRecord.Date.ToShortDateString()}")
                                </li>
                                <li class="list-group-item">
                                    @($"{translator.Translate(userLanguage, "Cost")}: {genericRecord.Cost.ToString("C")}")
                                </li>
                            break;
                            case ImportMode.OdometerRecord:
                                <li class="list-group-item">
                                    @($"{translator.Translate(userLanguage, "Date")}: {genericRecord.Date.ToShortDateString()}")
                                </li>
                                <li class="list-group-item">
                                    @($"{translator.Translate(userLanguage, "Odometer")}: {genericRecord.Mileage}")
                                </li>
                            break;
                        }
                        @foreach(ExtraField extraField in genericRecord.ExtraFields){
                            <li class="list-group-item">
                                @($"{extraField.Name}: {extraField.Value}")
                            </li>
                        }
                    </ul>
                </div>
            </div>
            <hr />
            @if(genericRecord.RequisitionHistory.Any()){
                <div class="row">
                    <div class="col-12">
                        <table class="table table-hover">
                            <thead class="sticky-top">
                                <tr class="d-flex">
                                    <th scope="col" class="col-2">@translator.Translate(userLanguage, "Part Number")</th>
                                    <th scope="col" class="col-6">@translator.Translate(userLanguage, "Description")</th>
                                    <th scope="col" class="col-2">@translator.Translate(userLanguage, "Quantity")</th>
                                    <th scope="col" class="col-2">@translator.Translate(userLanguage, "Cost")</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (SupplyUsageHistory usageHistory in genericRecord.RequisitionHistory)
                                {
                                    <tr class="d-flex">
                                        <td class="col-2 text-truncate">@usageHistory.PartNumber</td>
                                        <td class="col-6 text-truncate">@usageHistory.Description</td>
                                        <td class="col-2">@usageHistory.Quantity.ToString("F")</td>
                                        <td class="col-2">@usageHistory.Cost.ToString("C2")</td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                </div>
                <hr />
            }
            <div class="row stickerNoteContainer">
                <div class="col-12">
                    <div class="stickerNote ms-1 me-1 p-1">
                        @(genericRecord.Notes)
                    </div>
                </div>
            </div>
        </div>
    }
    <script>setMarkDownStickerNotes()</script>
} else if (Model.SupplyRecords.Any()){
    @foreach (SupplyRecord supplyRecord in Model.SupplyRecords)
    {
        <div class="d-flex flex-column recordSticker">
            <div class="d-flex">
                <img src="@config.GetLogoUrl()" class="lubelogger-logo" />
            </div>
            <hr />
            <div class="row">
                @if(Model.VehicleData.Id != default){
                    <div class="col-6">
                        <ul class="list-group">
                            <li class="list-group-item">
                                <span class="display-6">@($"{Model.VehicleData.Year} {Model.VehicleData.Make} {Model.VehicleData.Model}")</span>
                            </li>
                            <li class="list-group-item">
                                <span class="lead">@($"{StaticHelper.GetVehicleIdentifier(Model.VehicleData)}")</span>
                            </li>
                            @foreach (ExtraField extraField in Model.VehicleData.ExtraFields)
                            {
                                if (!string.IsNullOrWhiteSpace(extraField.Value))
                                {
                                    <li class="list-group-item">
                                        <span class="lead">@($"{extraField.Name}: {extraField.Value}")</span>
                                    </li>
                                }
                            }
                        </ul>
                    </div>
                    <div class="col-6">
                        <ul class="list-group">
                            <li class="list-group-item">
                                @($"{translator.Translate(userLanguage, "Description")}: {supplyRecord.Description}")
                            </li>
                            @if(!string.IsNullOrWhiteSpace(supplyRecord.PartNumber)){
                                <li class="list-group-item">
                                    @($"{translator.Translate(userLanguage, "Part Number")}: {supplyRecord.PartNumber}")
                                </li>
                            }
                            <li class="list-group-item">
                                @($"{translator.Translate(userLanguage, "Supplier/Vendor")}: {supplyRecord.PartSupplier}")
                            </li>
                            <li class="list-group-item">
                                @($"{translator.Translate(userLanguage, "Cost")}: {supplyRecord.Cost.ToString("C")}")
                            </li>
                            @foreach (ExtraField extraField in supplyRecord.ExtraFields)
                            {
                                <li class="list-group-item">
                                    @($"{extraField.Name}: {extraField.Value}")
                                </li>
                            }
                        </ul>
                    </div>
                } else {
                    <div class="col-6">
                        <ul class="list-group">
                            <li class="list-group-item">
                                @($"{translator.Translate(userLanguage, "Description")}: {supplyRecord.Description}")
                            </li>
                            @if (!string.IsNullOrWhiteSpace(supplyRecord.PartNumber))
                            {
                                <li class="list-group-item">
                                    @($"{translator.Translate(userLanguage, "Part Number")}: {supplyRecord.PartNumber}")
                                </li>
                            }
                            <li class="list-group-item">
                                @($"{translator.Translate(userLanguage, "Supplier/Vendor")}: {supplyRecord.PartSupplier}")
                            </li>
                            <li class="list-group-item">
                                @($"{translator.Translate(userLanguage, "Cost")}: {supplyRecord.Cost.ToString("C")}")
                            </li>
                        </ul>
                    </div>
                    <div class="col-6">
                        <ul class="list-group">
                            @foreach (ExtraField extraField in supplyRecord.ExtraFields)
                            {
                                <li class="list-group-item">
                                    @($"{extraField.Name}: {extraField.Value}")
                                </li>
                            }
                        </ul>
                    </div>
                }
            </div>
            <hr />
            <div class="row stickerNoteContainer">
                <div class="col-12">
                    <div class="stickerNote ms-1 me-1 p-1">
                        @(supplyRecord.Notes)
                    </div>
                </div>
            </div>
        </div>
    }
    <script>setMarkDownStickerNotes()</script>
} else if (Model.InspectionRecords.Any())
{
    @foreach (InspectionRecord inspectionRecord in Model.InspectionRecords)
    {
        var resultFields = inspectionRecord.Results.Where(x => x.FieldType == InspectionFieldType.Check || x.FieldType == InspectionFieldType.Radio);
        var textFields = inspectionRecord.Results.Where(x => x.FieldType == InspectionFieldType.Text);
        <div style="page-break-after: always;">
            <div class="d-flex">
                <img src="@config.GetLogoUrl()" class="lubelogger-logo" />
            </div>
            <hr />
            <div class="row">
                <div class="col-6">
                    <ul class="list-group">
                        <li class="list-group-item">
                            <span class="display-6">@($"{Model.VehicleData.Year} {Model.VehicleData.Make} {Model.VehicleData.Model}")</span>
                        </li>
                        <li class="list-group-item">
                            <span class="lead">@($"{StaticHelper.GetVehicleIdentifier(Model.VehicleData)}")</span>
                        </li>
                        @foreach (ExtraField extraField in Model.VehicleData.ExtraFields)
                        {
                            if (!string.IsNullOrWhiteSpace(extraField.Value))
                            {
                                <li class="list-group-item">
                                    <span class="lead">@($"{extraField.Name}: {extraField.Value}")</span>
                                </li>
                            }
                        }
                    </ul>
                </div>
                <div class="col-6">
                    <ul class="list-group">
                        <li class="list-group-item">
                            @($"{translator.Translate(userLanguage, "Description")}: {inspectionRecord.Description}")
                        </li>
                        <li class="list-group-item">
                            @($"{translator.Translate(userLanguage, "Result")}: {translator.Translate(userLanguage, inspectionRecord.Failed ? "Fail" : "Pass")}")
                        </li>
                        <li class="list-group-item">
                            @($"{translator.Translate(userLanguage, "Date")}: {inspectionRecord.Date.ToShortDateString()}")
                        </li>
                        <li class="list-group-item">
                            @($"{translator.Translate(userLanguage, "Odometer")}: {inspectionRecord.Mileage}")
                        </li>
                        <li class="list-group-item">
                            @($"{translator.Translate(userLanguage, "Cost")}: {inspectionRecord.Cost.ToString("C")}")
                        </li>
                        @foreach (InspectionRecordResult textResult in textFields)
                        {
                            <li class="list-group-item">
                                @($"{textResult.Description}: {textResult.Values?.FirstOrDefault(x => x.IsSelected)?.Description}")
                            </li>
                        }
                    </ul>
                </div>
            </div>
            <hr />
            <div class="row">
                <div class="col-12">
                @if (resultFields.Any())
                {
                    <table class="table table-hover">
                        <thead class="sticky-top">
                            <tr class="d-flex">
                                <th scope="col" class="col-9 flex-grow-1 flex-shrink-1 text-truncate">@translator.Translate(userLanguage, "Description")</th>
                                <th scope="col" class="col-3 flex-grow-1 flex-shrink-1 text-truncate">@translator.Translate(userLanguage, "Result")</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (InspectionRecordResult fieldResult in resultFields)
                            {
                                <tr class="d-flex user-select-none">
                                    <td class="col-9 flex-grow-1 flex-shrink-1 text-truncate">
                                        @fieldResult.Description
                                        <div class="d-flex flex-wrap">
                                            @foreach (InspectionRecordResultValue fieldValue in fieldResult.Values)
                                            {
                                                if (fieldResult.FieldType == InspectionFieldType.Radio)
                                                {
                                                        <span class="inspection-value me-2 @(fieldValue.IsFail && fieldValue.IsSelected ? "inspection-value-fail text-danger" : "") @(fieldValue.IsSelected ? "inspection-value-selected" : "")">@fieldValue.Description</span>
                                                }
                                                else if (fieldResult.FieldType == InspectionFieldType.Check)
                                                {
                                                        <span class="inspection-value me-2 @(fieldValue.IsFail && !fieldValue.IsSelected ? "text-danger" : "")"><i class="bi @(fieldValue.IsSelected ? "bi-check-lg" : "bi-x-lg") me-2"></i>@fieldValue.Description</span>
                                                }
                                            }
                                        </div>
                                    </td>
                                    <td class="col-3 flex-grow-1 flex-shrink-1 text-truncate">
                                        @(fieldResult.Failed? translator.Translate(userLanguage, "Fail") : translator.Translate(userLanguage, "Pass"))
                                    </td>
                                </tr>
                                @if (!string.IsNullOrWhiteSpace(fieldResult.Notes))
                                {
                                    <tr class="d-flex user-select-none">
                                        <td class="col-12 flex-grow-1 flex-shrink-1 flex-wrap">
                                            <div class="stickerNote ms-1 me-1 p-1">
                                                @(fieldResult.Notes)
                                            </div>
                                        </td>
                                    </tr>
                                }
                            }
                        </tbody>
                    </table>
                }
                </div>
            </div>
        </div>
    }
    <script>setMarkDownStickerNotes()</script>
}